package com.net;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.AnnotationConfiguration;
import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.tool.hbm2ddl.SchemaExport;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
import org.springframework.orm.hibernate3.HibernateTemplate;

import com.net.model.Category;
import com.net.model.Commodity;
import com.net.model.Provider;

public class HibernateCreateDataBase {
	private static SessionFactory sf;
	
	@BeforeClass
	public static void beforeClass() {
		sf = new AnnotationConfiguration().configure().buildSessionFactory();
	}
	@AfterClass
	public static void afterClass() {
		sf.close();
	}
	
	@Test
	public void testSchemaExport() {
		new SchemaExport(new AnnotationConfiguration().configure()).create(false, true);
	}
	
	public static void main(String[] args) {
		beforeClass();
		//testDelete();
		//testSchemaExport();
		afterClass();
	}
	/*@Test
	public void testLoad() {
		Session s = sf.openSession();
		s.beginTransaction();
		Commodity c = (Commodity) s.load(Commodity.class, 1);
		System.out.println(c.getCommodity_name()+":" + c.getCategory().getCategory_name());
	}
	@Test
	public void testDelete() {
		Category u = new Category();
		u.setId(2);
		//c.setCategory(null);
		//c.setProvider(null);
		Session s = sf.openSession();
		s.beginTransaction();
		s.delete(u);
		s.getTransaction().commit();
		//System.out.println(u.getCommodity_name()+":" + u.getCategory().getCategory_name()+":"+c.getProvider().getProvider_name());
	}
	public void find(){
		HibernateTemplate hibernateTemplate = new HibernateTemplate();
		hibernateTemplate.findByCriteria(DetachedCriteria.forClass(Commodity.class));
	}*/
}
